package persistence;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import model.Editora;

public class ConsultaEditoraDaoImpl implements ConsultaEditoraDao {

	Connection c;

	public ConsultaEditoraDaoImpl() {
		GenericDao gDao = new GenericDao();
		c = gDao.getConnection();
	}

	public List<Editora> listaEditora(Editora editora) throws SQLException {

		List<Editora> lista = new ArrayList<Editora>();
		StringBuffer sb = new StringBuffer();

		sb.append("SELECT * FROM Editoras");

		PreparedStatement ps = c.prepareStatement(sb.toString());
//		ps.setInt(1, editora.getIdEditora());

		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			Editora e = new Editora();

			e.setIdEditora(rs.getInt("idEditora"));
			e.setNomeEditora(rs.getString("nomeEditora"));
			e.setTelefone(rs.getInt("telefone"));

			lista.add(e);
		}
		rs.close();
		ps.close();

		return lista;
	}

}
